import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class test1 {
    //需求：
    //压缩文件
    public static void main(String[] args) throws IOException {
        //数据源
        File src=new File("D:\\a.txt");
        //目的地
        File dest=new File("D:\\");
        //调用方法压缩
        tozip(src,dest);
    }

    private static void tozip(File src, File dest) throws IOException {
        //创建压缩流关联压缩包
        ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(new File(dest,"a.zip")));
        //表示压缩包里的每一个文件
        ZipEntry entry=new ZipEntry("a.txt");
        //
        zos.putNextEntry(entry);
        FileInputStream fis=new FileInputStream(src);
        int b;
        while((b=fis.read())!=-1){
            zos.write(b);
        }
        zos.closeEntry();


    }
}
